package org.microlites.data;

import org.microlites.view.AnimationThread;

import android.graphics.Color;
import android.view.Menu;
import android.view.SurfaceHolder;

/**
 * Application-wide accesible data holder used to share data between the
 * different application activities and threads.
 * Applies a Singleton pattern and provides a mutex for inter-thread synchronization. 
 */
public class Data {
	// Singleton pattern
	protected static Data _instance = null;
	/** Obtains a reference to the unique Data instance in the system 
	 * @return Instance of Data 
	 * */
	public static Data getInstance() {
		if (_instance == null)
			_instance = new Data();
		
		return _instance;
	}
	
	/* Temporary storage */
	// TODO: Clean and organize this
	
	/* Data Related */
	/** Inter-thread synchronization mutex */
	public Object mutex;
	
	/* Aplication Mode Related */ 
	/** Active visualization view thread reference */
	public AnimationThread currentViewThread = null;
	/** Active visualization surface holder reference */
	public SurfaceHolder currentViewHolder = null;
	
	/* Visualization Related */
	/** Realtime visualization pause flag.
	 *  Freezes current frame display on screen when activated.*/
	public boolean pause = false;
	/** 
	 * Max Positive Value of visualization Y scale. 
	 * Required scale factor is computed from it */
	public float yScaleTopValue = 12000.0f;
	/**
	 * Visualization base position relative to visualization height.
	 * Ranges from 0 to 1, default 0.5
	 */
	public float drawBaseHeight = 0.5f;
	/** Visualization width in seconds */
	public float viewWidth = 1.5f;
	
	/* Visualization Colors */
	public int color1 = Color.RED;
	public int color2 = Color.BLUE;
	
	/* Generator DataSource Related */
	/** 
	 * Generate only 0s flag. When true, InputGeneratorDataSource will
	 * only generate 0 valued samples.
	 */
	public boolean generateZeros = false;
	/**
	 * InputGeneratorDataSource generated samples amplitude.
	 * Non-zero valued samples generated by an instance of that DataSource
	 * will have this value.
	 */
	public short generateHeight = 2000;
	
	public Menu appMenu = null;

	public String lastBluetoothDevice = null;
	
	/** Initializes required data */
	protected Data() {
		// TODO: Data initialization
		mutex = new Object();
	}
	
	/** (Re)Set default view values */
	public void resetView() {
		drawBaseHeight = 0.5f;
		yScaleTopValue = 12000.0f;
	}
}
